import numpy as np
import cv2 as cv
im =np.zeros((300,300,3),np.uint8)
im[100:200,100:2001]=255
imgray =cv.cvtColor(im,cv.COLOR_BGR2GRAY)
ret,thresh=cv.threshold(imgray,127,255,0)
retrievalMode =cv.RETR_TREE
approxMethod =cv.CHAIN_APPROX_NONE
contours, hierarchy = cv.findContours(thresh, retrievalMode, approxMethod)

img =np.zeros((300,300,3),np.uint8)
contoursIdx=0
color,thickness=(0,0,255),1
cv.drawContours(img,contours,contoursIdx,color,thickness)
cv.imshow("im",im)
cv.imshow("img",img)
cv.waitKey(0)
cv.destroyAllWindows()

img2 =np.zeros((300,300,3),np.uint8)
cnt = contours[0]
for fakePt in cnt:
#print (fakePt)
   realPt = fakePt[0]
   cv.line(img2, realPt, realPt,color,thickness)
cv.imshow("img2", img2)
cv.waitKey(0)
cv.destroyAllWindows()